# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: Simone Sclavi 'Ito' <darkhado@gmail.com>

pkgname=libjpeg-turbo
pkgver=2.1.1
pkgrel=1
pkgdesc='JPEG image codec with accelerated baseline compression and decompression'
url='https://libjpeg-turbo.org/'
arch=('x86_64')
license=('BSD')
depends=('glibc')
makedepends=('cmake' 'nasm' 'java-environment>11')
optdepends=('java-runtime>11: for TurboJPEG Java wrapper')
provides=('libjpeg' 'libjpeg.so' 'libturbojpeg.so')
source=("https://sourceforge.net/projects/${pkgname}/files/${pkgver}/${pkgname}-${pkgver}.tar.gz"{,.sig})
sha512sums=('9cf61b4677b38e254063248a3fdbe138634d23a35ae8f2ee2661bdb3248b1d0500bd43201b8d9fe66c779d578074fd9ed19bc097ba22e10143530c2a19738673'
            'SKIP')
b2sums=('ad3fc108e0136220586cc59a277735d573a82d740146d2ac091cbb50af84019b7c623ca1c9c2e6e0f8a672b6fde7ed23441b199eef2435a52013abd73a3a7157'
        'SKIP')
validpgpkeys=('0338C8D8D9FDA62CF9C421BD7EC2DBB6F4DBF434') # The libjpeg-turbo Project (Signing key for official binaries) <information@libjpeg-turbo.org>

build() {
  cd "${pkgname}-${pkgver}"
  cmake -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_INSTALL_LIBDIR=/usr/lib \
        -DCMAKE_BUILD_TYPE='None' \
        -DWITH_JAVA=ON \
        -DWITH_JPEG8=ON \
        -W no-dev \
        -B build \
        -S .
  make VERBOSE=1 -C build
}

check() {
  cd "${pkgname}-${pkgver}"
  make test -C build
}

package() {
  cd "${pkgname}-${pkgver}"
  make VERBOSE=1 DESTDIR="${pkgdir}" \
       docdir="/usr/share/doc/${pkgname}" \
       exampledir="/usr/share/doc/${pkgname}" \
       install -C build

  install -d "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -s ../../doc/${pkgname}/LICENSE.md "${pkgdir}/usr/share/licenses/${pkgname}"
  # header required by some dependants
  # https://bugs.archlinux.org/task/24787
  install -m 644 jpegint.h "${pkgdir}/usr/include"
}
